/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.sales.hanserver.action.hancadso.purchaserequest.subitem;

import br.com.sales.hanserver.action.hancadso.purchaserequest.consts.HanCadSOServerConsts;
import static br.com.sales.hanserver.dao.Dao.closeConn;
import static br.com.sales.hanserver.dao.Dao.getConn;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author v
 */
public class GetDataSubItemAction {

    public GetDataSubItemAction() {
    }

    public List<Map> getDataGrid(long sequence) {
        List<Map> resultData = new LinkedList<>();
        try {
            PreparedStatement st = getConn().prepareStatement(HanCadSOServerConsts.GET_REQUEST_SUBITEM);
            st.setLong(1, sequence);

            ResultSet rs = st.executeQuery();
            while (rs.next()) {
                Map map = new LinkedHashMap(3);
                map.put("DS_PRODUTO", rs.getString("DS_PRODUTO"));
                map.put("QT_QUANTIDADE", rs.getInt("QT_QUANTIDADE"));
                resultData.add(map);
            }

            return resultData;

        } catch (Exception ex) {
            Logger.getLogger(GetDataSubItemAction.class.getName()).log(Level.SEVERE, "Error getDataGrid", ex);
        } finally {
            closeConn();
        }
        return resultData;
    }

    public List<Map> getDataIDGrid(long sequence) {
        List<Map> resultData = new LinkedList<>();
        try {
            PreparedStatement st = getConn().prepareStatement(HanCadSOServerConsts.GET_REQUEST_ID_SUBITEM);
            st.setLong(1, sequence);

            ResultSet rs = st.executeQuery();
            while (rs.next()) {
                Map map = new LinkedHashMap(3);
                map.put("NR_SEQ_PRODUTO", rs.getLong("NR_SEQ_PRODUTO"));
                map.put("QT_QUANTIDADE", rs.getInt("QT_QUANTIDADE"));
                resultData.add(map);
            }

            return resultData;

        } catch (Exception ex) {
            Logger.getLogger(GetDataSubItemAction.class.getName()).log(Level.SEVERE, "Error getDataGrid", ex);
        } finally {
            closeConn();
        }
        return resultData;
    }
}
